using System;
using System.Data;
using ASP.App_Code.Data;
using DayPilot.Utils;

public partial class Scheduler_Year : System.Web.UI.Page
{
    private DataTable table;

    protected void Page_Load(object sender, EventArgs e)
    {
        initData();

        // starting first day of the first week (using ISO 8601, i.e. week starts on Monday)
        DayPilotScheduler1.StartDate = Week.FirstDayOfWeek(new DateTime(2010, 1, 1), DayOfWeek.Monday);

        // ending at the end of the last week
        DayPilotScheduler1.Days = (int) (Week.FirstDayOfWeek(new DateTime(2011, 1, 1)).AddDays(7) - DayPilotScheduler1.StartDate).TotalDays;

        if (!IsPostBack)
        {
            DayPilotScheduler1.DataSource = table;
            DayPilotScheduler1.SetScrollX(DateTime.Today);
            DataBind();
        }
    }

    protected void DayPilotScheduler1_BeforeTimeHeaderRender(object sender, DayPilot.Web.Ui.Events.BeforeTimeHeaderRenderEventArgs e)
    {
        if (!e.IsColGroup)
        {
            e.InnerHTML = Week.WeekNrISO8601(e.Start).ToString();
        }

    }

    /// <summary>
    /// Make sure a copy of the data is in the Session so users can try changes on their own copy.
    /// </summary>
    private void initData()
    {

        if (Session[PageHash] == null)
        {
            Session[PageHash] = DataGeneratorScheduler.GetData();
        }
        table = (DataTable)Session[PageHash];
    }

    protected string PageHash
    {
        get
        {
            return Hash.ForPage(this);
        }
    }

}
